﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Model
{
    public class WeddingContainer
    {
        static object locker = new object();
        static WeddingContainer instance;
        private List<Wedding> weddings { get; set; }
        public static WeddingContainer sharedInstance
        {
            get
            {
                if (instance == null)
                    instance = new WeddingContainer();
                return instance;
            }
        }
        public WeddingContainer()
        {
            weddings = new List<Wedding>();
        }
        public void Add(Wedding wedding)
        {
            lock(locker)
            {
                if (WeddingWithIdentifier(wedding.identifier) == null)
                    weddings.Add(wedding);
            }
        }
        public void DeleteWedding(Wedding wedding)
        {
            lock(locker)
            {
                weddings.Remove(wedding);
            }
        }

        public Wedding WeddingWithIdentifier(string identifier)
        {
            return weddings.Find(w=>
                {
                    return w.identifier == identifier;
                });
        }
    }
}